package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysPrinterSettingQuery;
import com.jcfk.system.domain.dto.SysPrinterSettingDTO;
import com.jcfk.system.service.SysPrinterSettingService;
import com.jcfk.common.core.utils.ExcelUtils;

import java.util.List;

/**
 * 打印机设置
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-08-12
 */
@Api(tags = {"打印机设置管理"})
@RestController
@RequestMapping("sysPrinterSetting")
public class SysPrinterSettingController {
    @Autowired
    private SysPrinterSettingService sysPrinterSettingService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysPrinterSettingQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询打印机设置")
    @PostMapping("/queryByPage")
    public RetPage<SysPrinterSettingDTO> queryByPage(@RequestBody ReqPageParam<SysPrinterSettingQuery> requestParam) {
        DataPage<SysPrinterSettingDTO> page = new DataPage<SysPrinterSettingDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysPrinterSettingDTO.class);
        page = sysPrinterSettingService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  打印机设置
     * 根据id 查询详情
     */
    @ApiOperation("查询打印机设置")
    @GetMapping("/get/{id}")
    public RetResult<SysPrinterSettingDTO> get(@PathVariable("id") String id) {
            SysPrinterSettingDTO item = sysPrinterSettingService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理打印机设置
     */
    @ApiOperation("保存打印机设置")
    @PostMapping("/save")
    @RequestLogHeader(modular = "打印机设置管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysPrinterSettingDTO sysPrinterSetting) {
        // 数据校验
        RetResult ret = sysPrinterSettingService.isValid(sysPrinterSetting);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysPrinterSetting.getId())){
            // 新增
            sysPrinterSettingService.insert(sysPrinterSetting);
        } else{
            // 更新
            sysPrinterSettingService.update(sysPrinterSetting);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除打印机设置
     */
    @ApiOperation("批量删除打印机设置")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "打印机设置管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysPrinterSettingDTO sysPrinterSetting) {
        return RetResult.ok(sysPrinterSettingService.logicDeleteList(sysPrinterSetting));
    }

    /**
     *  删除打印机设置
     */
    @ApiOperation("删除打印机设置")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "打印机设置管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        sysPrinterSettingService.deleteItem(id);
        return RetResult.ok();
    }

    @ApiOperation("获取打印机列表")
    @PostMapping("/getList")
    public RetResult<?> getList(@RequestBody SysPrinterSettingQuery query) {
        List<SysPrinterSettingDTO> list= sysPrinterSettingService.getList(query);
        return RetResult.ok(list);
    }
}
